# -*- coding:utf-8 -*-
"""
Convert Hex color to R,G,B Text
Example:
#000000  -> 0,0,0
#FFFFFF  -> 255, 255, 255
"""

import re

def hex2rgb(hexstr):
    pat = re.compile(r'^#[a-fA-F0-9]{6}$')
    hexstr = hexstr.strip()
    assert(re.match(pat, hexstr))
    m = re.match(r'^#(\w{2})(\w{2})(\w{2})', hexstr)
    r,g,b = [int(x=x, base=16) for x in m.groups()]
    return r,g,b

def rgb2hex(r,g,b):
    def my_hex(num):
        return hex(num)[-2:].upper()
    r,g,b = [my_hex(x) for x in (r,g,b)]
    return '#%s%s%s' % (r,g,b)

if __name__ == '__main__':
    print(hex2rgb('#1E90FF'))
    print(rgb2hex(255,255,255))